package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TNumberPersistenceInfo;
import com.ruoyi.system.service.ITNumberPersistenceInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 运单编号Controller
 * 
 * @author wzy
 * @date 2024-08-30 16:42:11
 */
@RestController
@RequestMapping("/system/number")
public class TNumberPersistenceInfoController extends BaseController
{
    @Autowired
    private ITNumberPersistenceInfoService tNumberPersistenceInfoService;

    private static Logger logger = LoggerFactory.getLogger(TNumberPersistenceInfoController.class);
    /**
     * 查询运单编号列表
     */
    @PreAuthorize("@ss.hasPermi('system:number:list')")
    @GetMapping("/list")
    public TableDataInfo list(TNumberPersistenceInfo tNumberPersistenceInfo)
    {
        startPage();
        List<TNumberPersistenceInfo> list = tNumberPersistenceInfoService.selectTNumberPersistenceInfoList(tNumberPersistenceInfo);
        return getDataTable(list);
    }

    /**
     * 导出运单编号列表
     */
    @PreAuthorize("@ss.hasPermi('system:number:export')")
    @Log(title = "运单编号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TNumberPersistenceInfo tNumberPersistenceInfo)
    {
        List<TNumberPersistenceInfo> list = tNumberPersistenceInfoService.selectTNumberPersistenceInfoList(tNumberPersistenceInfo);
        ExcelUtil<TNumberPersistenceInfo> util = new ExcelUtil<TNumberPersistenceInfo>(TNumberPersistenceInfo.class);
        util.exportExcel(response, list, "运单编号数据");
    }

    /**
     * 获取运单编号详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:number:query')")
    @GetMapping(value = "/{numberPersistenceId}")
    public AjaxResult getInfo(@PathVariable("numberPersistenceId") Long numberPersistenceId)
    {
        return success(tNumberPersistenceInfoService.selectTNumberPersistenceInfoByNumberPersistenceId(numberPersistenceId));
    }

    /**
     * 新增运单编号
     */
    @PreAuthorize("@ss.hasPermi('system:number:add')")
    @Log(title = "运单编号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TNumberPersistenceInfo tNumberPersistenceInfo)
    {
        tNumberPersistenceInfo.setCreateBy(getNickName());
        return toAjax(tNumberPersistenceInfoService.insertTNumberPersistenceInfo(tNumberPersistenceInfo));
    }

    /**
     * 修改运单编号
     */
    @PreAuthorize("@ss.hasPermi('system:number:edit')")
    @Log(title = "运单编号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TNumberPersistenceInfo tNumberPersistenceInfo)
    {
        tNumberPersistenceInfo.setUpdateBy(getNickName());
        return toAjax(tNumberPersistenceInfoService.updateTNumberPersistenceInfo(tNumberPersistenceInfo));
    }

    /**
     * 删除运单编号
     */
    @PreAuthorize("@ss.hasPermi('system:number:remove')")
    @Log(title = "运单编号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{numberPersistenceIds}")
    public AjaxResult remove(@PathVariable Long[] numberPersistenceIds)
    {
        return toAjax(tNumberPersistenceInfoService.deleteTNumberPersistenceInfoByNumberPersistenceIds(numberPersistenceIds));
    }

    /**
     * 获取运单编号一个
     */
//    @PreAuthorize("@ss.hasPermi('system:number:query')")
    @GetMapping("/getone")
    public synchronized AjaxResult getOne()
    {
//        Format decimalFormat = new DecimalFormat("000000000");
        Long numberPersistenceId = 1L;
//        logger.debug("YYY " + "numberPersistenceId = " + numberPersistenceId);
        TNumberPersistenceInfo tNumberPersistenceInfo;
        tNumberPersistenceInfo = tNumberPersistenceInfoService.selectTNumberPersistenceInfoByNumberPersistenceId(numberPersistenceId);
        tNumberPersistenceInfo.addOne();
        tNumberPersistenceInfoService.updateTNumberPersistenceInfo(tNumberPersistenceInfo);
//        logger.debug("YYY " + "tNumberPersistenceInfo = " + tNumberPersistenceInfo);
//        logger.debug("YYY " + "tNumberPersistenceInfo = " + decimalFormat.format(tNumberPersistenceInfo.getNumber()));

        return success(tNumberPersistenceInfo);
//        return success(decimalFormat.format(tNumberPersistenceInfo.getNumber()));
    }
}
